const glob = require("glob")
const fs = require("fs");
const path = require("path");
const envPath = path.resolve(__dirname, ".", ".env.development");
const envText = fs.readFileSync(envPath, "utf8");
const VUE_APP_TITLES = /VUE_APP_TITLES='(.+)'\r/g.exec(envText)[1];
const titles=JSON.parse(VUE_APP_TITLES);
try {
    entries = glob('src/pages/*/main.js', { sync: true })
} catch (err) {
    entries = []
    throw err
}
let pages = {}
let commonConfig = {
    template: 'public/index.html',
}

entries.forEach((page) => {
    const pagePath=page.split('src/pages/')[1];
    const filename=pagePath.substring(0,pagePath.indexOf('\/'));
    pages[filename] = {
        entry: page,
        filename: filename + '.html',
        title: titles[filename],
        chunks: ['chunk-vendors', 'chunk-common', filename],
        ...commonConfig
    }
})

module.exports = pages